home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-04-07 | 1.5 KB | 77 lines | [TEXT/MPS ] |
- //---------------------------------------------------------------------
- //
- // Copyright © 1992 David Peterson.
- // All rights reserved.
- //
- // Permission to use, copy, modify, and distribute this software for
- // any purpose and without fee is hereby granted, provided that the
- // above copyright notice appear in all copies and that both that
- // copyright notice and this permission notice appear in supporting
- // documentation.
- //
- //---------------------------------------------------------------------
-
- #include "CList.h"
-
- CList::~CList()
- {
- CItem* it;
-
- while (it = this->First()) {
- this->TakeOff(it);
- delete it;
- }
- }
-
- CItem*
- CList::PutOn(CItem* nu)
- {
- nu->fNext = 0; // we're going on the end. period.
-
- if (fTail) // there is something else here…
- fTail->fNext = nu;
- else // we're the only one, head points to us
- fHead = nu;
-
- fTail = nu;
-
- return nu;
- }
-
- CItem*
- CList::TakeOff(CItem* off)
- {
- CItem* prev = 0;
-
- if (off == fHead) { // are we at the head?
- fHead = off->fNext;
- }
- else {
- prev = fHead; // prev is element before us
- while (prev->fNext && (prev->fNext != off))
- prev = prev->fNext;
-
- if (prev->fNext == off) // were we even found?
- prev->fNext = off->fNext;
- }
-
- if (off == fTail) // did we also happen to be at the tail?
- fTail = prev;
-
- return off;
- }
-
- CItem*
- CList::IsOn(CItem* test)
- {
- CItem* it = fHead;
-
- // while there are more elements and they aren't us move forward
- while (it && (it != test))
- it = it->fNext;
-
- // return us or null
- return it;
- }
-
-